﻿using MediatR;
using SystemHYS.API.Application.command.DeliveryCommand;
using SystemHYS.Infrstructre.Interface;

namespace SystemHYS.API.Application.commandler.DeliveryCommandler
{
    public class DeliveryUpdateStateCommandler : IRequestHandler<DeliveryUpdateStateCommand, int>
    {
        IDeliveryRepository deliveryRepository;
        public DeliveryUpdateStateCommandler(IDeliveryRepository deliveryRepository)
        {
            this.deliveryRepository = deliveryRepository;
        }
        public async Task<int> Handle(DeliveryUpdateStateCommand request, CancellationToken cancellationToken)
        {
            var list = await deliveryRepository.GetModelAsnc(request.deliveryId);
            if (list.state == 1)
            {
                list.state = 2;
            }
            else
            {
                list.state = 1;
            }
            return await deliveryRepository.UpdateAsyn(list);
        }
    }
}
